package org.fisco.bcos.asset.client;

import java.math.BigInteger;
import java.util.List;
import org.fisco.bcos.asset.contract.CharityDonation;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.eventsub.EventCallback;
import org.fisco.bcos.sdk.model.TransactionReceipt;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;
// 添加Tuple相关的导入
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple3;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple7;

public class CharityDonationClient_01 {
    private CharityDonation charityDonation;
    private Client client;
    private CryptoKeyPair credential;

    public CharityDonationClient_01(String contractAddress, Client client, CryptoKeyPair credential) {
        this.client = client;
        this.credential = credential;
        this.charityDonation = CharityDonation.load(contractAddress, client, credential);
    }

    // 部署合约
    public static CharityDonationClient_01 deploy(Client client, CryptoKeyPair credential) throws ContractException {
        CharityDonation contract = CharityDonation.deploy(client, credential);
        return new CharityDonationClient_01(contract.getContractAddress(), client, credential);
    }

    // 设置监管者
    public TransactionReceipt setRegulator(String regulatorAddress) {
        return charityDonation.setRegulator(regulatorAddress);
    }

    // 注册受益人
    public TransactionReceipt registerBeneficiary(String beneficiaryAddress) {
        return charityDonation.registerBeneficiary(beneficiaryAddress);
    }

    // 创建捐赠项目
    public TransactionReceipt createDonationProject(String projectName, String description,
                                                    String beneficiaryAddress, BigInteger targetAmount) {
        return charityDonation.createDonationProject(projectName, description, beneficiaryAddress, targetAmount);
    }

    // 审批项目
    public TransactionReceipt approveProject(BigInteger projectId) {
        return charityDonation.approveProject(projectId);
    }

    // 提交申请
    public TransactionReceipt submitApplication(String description, BigInteger requestedAmount) {
        return charityDonation.submitApplication(description, requestedAmount);
    }

    // 审批申请
    public TransactionReceipt approveApplication(BigInteger applicationId) {
        return charityDonation.approveApplication(applicationId);
    }

    // 捐赠
    public TransactionReceipt donate(BigInteger projectId, BigInteger amount) {
        return charityDonation.donate(projectId, amount);
    }

    // 查询项目详情
    public Tuple7<String, String, String, BigInteger, BigInteger, BigInteger, Boolean>
    getProjectDetails(BigInteger projectId) throws ContractException {
        return charityDonation.getProjectDetails(projectId);
    }

    // 查询捐赠记录
    public Tuple3<List<BigInteger>, List<BigInteger>, List<String>>
    getDonationRecords(BigInteger projectId) throws ContractException {
        return charityDonation.getDonationRecords(projectId);
    }

    // 查询受益人统计信息
    public Tuple3<BigInteger, BigInteger, BigInteger>
    getBeneficiaryStats(String beneficiaryAddress) throws ContractException {
        return charityDonation.getBeneficiaryStats(beneficiaryAddress);
    }

    // 查询用户角色
    public BigInteger getUserRole(String userAddress) throws ContractException {
        return charityDonation.userRoles(userAddress);
    }

    // 查询项目总数
    public BigInteger getProjectCount() throws ContractException {
        return charityDonation.projectCount();
    }

    // 查询申请总数
    public BigInteger getApplicationCount() throws ContractException {
        return charityDonation.applicationCount();
    }

    // 查询特定捐赠者的捐赠金额
    public BigInteger getDonationAmount(BigInteger projectId, String donorAddress) throws ContractException {
        return charityDonation.getDonationAmount(projectId, donorAddress);
    }

    // 获取合约地址
    public String getContractAddress() {
        return charityDonation.getContractAddress();
    }

    // 获取监管者地址
    public String getRegulator() throws ContractException {
        return charityDonation.regulator();
    }

    // 获取慈善组织地址
    public String getCharityOrg() throws ContractException {
        return charityDonation.charityOrg();
    }

    // 事件监听相关方法
    public void subscribeProjectCreatedEvent(EventCallback callback) {
        charityDonation.subscribeProjectCreatedEvent(callback);
    }

    public void subscribeDonationMadeEvent(EventCallback callback) {
        charityDonation.subscribeDonationMadeEvent(callback);
    }

    public void subscribeApplicationSubmittedEvent(EventCallback callback) {
        charityDonation.subscribeApplicationSubmittedEvent(callback);
    }

    public void subscribeApplicationApprovedEvent(EventCallback callback) {
        charityDonation.subscribeApplicationApprovedEvent(callback);
    }

    public void subscribeProjectApprovedEvent(EventCallback callback) {
        charityDonation.subscribeProjectApprovedEvent(callback);
    }

    public void subscribeFundsReleasedEvent(EventCallback callback) {
        charityDonation.subscribeFundsReleasedEvent(callback);
    }
}